home *** CD-ROM | disk | FTP | other *** search
- Path: news.cern.ch!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong with this loop?
- Date: 19 Apr 96 15:53:21 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.829929201@news.cern.ch>
- References: <4l86la$1t9@uwm.edu>
- NNTP-Posting-Host: hpplus01.cern.ch
- Mime-Version: 1.0
- Content-Type: text/plain; charset=US-ASCII
- Content-Transfer-Encoding: 7bit
- X-Newsreader: NN version 6.5.0 #18 (NOV)
-
- In <4l86la$1t9@uwm.edu> mardavuy@alpha2.csd.uwm.edu (Mario David Uy) writes:
-
- >#include <stdio.h>
- >int main(void)
- >{
- > int dia;
- >
- > char cd;
- >
- > ...
- >
- > scanf("%c", &cd);
- > while (cd != 'm' || cd ! 'f' || cd != 'o')
- > {
- > printf("Re-enter m, f, or o.\n");
- > scanf(%c", &cd);
- > }
- > ...
- >}
- >
- >It works fine, except that it gives me the printf() twice.
-
- It gives you the printf() twice because this is precisely what you were
- asking for. Hint: you forgot to drop the newline from stdin.
-
- BTW, using scanf to get user input will cause even more shots in your
- foot in the future :-)
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-